package com.wkk.nursinghome.service.impl;

import com.wkk.nursinghome.convert.Age;
import com.wkk.nursinghome.dao.ICheckinDao;
import com.wkk.nursinghome.domain.Checkin;
import com.wkk.nursinghome.service.ICheckinService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CheckinServiceImpl implements ICheckinService {
    //注入对象
    @Resource
    private ICheckinDao checkinDao;

    //实现方法，获取所有信息
    @Override
    public List<Checkin> selectAll() {
        List<Checkin> checkins=checkinDao.selectAll();
        for (Checkin checkin:checkins){
            String age=checkin.getAge();
            age= Age.getPersonAgeByBirthDate(age);
            checkin.setAge(age);
        }
        return checkins;
    }

    //增加信息
    @Override
    public void addCheckin(Checkin checkin) {
         checkinDao.insertCheckin(checkin);
    }

    //修改信息
    @Override
    public boolean updateCheckin(Checkin checkin) {
        return checkinDao.updateCheckin(checkin) > 0;
    }

    //根据编号查询信息
    @Override
    public Checkin queryById(Integer id) {
        return checkinDao.selectById(id);
    }

    //根据编号删除信息
    @Override
    public boolean deleteCheckinById(Integer id) {
        return checkinDao.deleteCheckinById(id) > 0;
    }

    //根据条件查询
    @Override
    public List<Checkin> selectByCondition(Checkin checkin) {
        List<Checkin> checkins=checkinDao.getCheckinByCondition(checkin);
        for (Checkin checkin1:checkins){
            String age=checkin1.getAge();
            age= Age.getPersonAgeByBirthDate(age);
            checkin1.setAge(age);
        }
        return checkins;
    }
}
